import 'package:flutter/material.dart';
import 'package:shenling_wuliu/login/login.dart';
import 'package:shenling_wuliu/mine/system.dart';
import 'package:shenling_wuliu/tab_bar/index.dart';
import 'package:shenling_wuliu/utils/token.dart';

void main() {
  // WidgetsFlutterBinding.ensureInitialized(); // 必须加这一行
  //  TokenManager().init();
  runApp(MaterialApp(
    routes: {
      '/': (context) => Login(),
      '/tabbar': (context) => TabBarWidget(),
      '/system': (context) => SystemWidget(),
    },
    onGenerateRoute: (settings) {
      final tokenManager = TokenManager();
      final token = tokenManager.getToken() ?? '';
      if (token.isEmpty && settings.name != '/') {
        return MaterialPageRoute(builder: (context) => const Login());
      }
      return MaterialPageRoute(builder: (context) => const TabBarWidget());
    },
    initialRoute: '/',
  ));
}